package com.cjjd.c.feature.mine.information;

import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.AddressListBean;
import com.cjjd.c.bean.ContactBean;
import com.cjjd.c.bean.ReceiptBean;
import com.cjjd.c.bean.TravellerListBean;
import com.cjjd.c.utils.StringUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/16.
 */

public class InformationAdapter extends MyBaseAdapter {

    // 旅客
    public static final int TRAVELLER = 0x00000001;
    // 地址
    public static final int ADDRESS = 0x00000002;
    // 联系人
    public static final int CONTACT = 0x00000003;
    // 发票
    public static final int RECEIPTMANAGER = 0x00000004;

    private int inType = 0;

    public InformationAdapter(FragmentActivity mContext, int AdapterType) {
        super(mContext);
        this.inType = AdapterType;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_traveller, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (inType == TRAVELLER) {
            TravellerListBean itemBean = (TravellerListBean) getItem(position);
            viewHolder.tvName.setText(itemBean.name);
            viewHolder.tvIdNum.setText("身份证  "+StringUtil.getSignIdNum(itemBean.idCardNum));
        }
        if (inType == ADDRESS) {
            AddressListBean itemBean = (AddressListBean) getItem(position);
            viewHolder.tvName.setText(itemBean.consignee);
            viewHolder.tvIdNum.setText(itemBean.address);
        }

        if (inType == CONTACT) {
            ContactBean itemBean = (ContactBean) getItem(position);
            viewHolder.tvName.setText(itemBean.name);
            viewHolder.tvIdNum.setText(StringUtil.getSignPhone(itemBean.mobile));
        }

        if (inType == RECEIPTMANAGER) {
            ReceiptBean itemBean = (ReceiptBean) getItem(position);
            viewHolder.tvName.setText(itemBean.company);
            viewHolder.tvIdNum.setText(itemBean.address);
            if(itemBean.invoiceType.equalsIgnoreCase("1")){
                viewHolder.tvIdNum.setText("个人");
            }
        }


        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_id_num)
        TextView tvIdNum;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
